/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import core.User;
import core.UserLevel;
import javax.annotation.PostConstruct;

/**
 *
 * @author Peter
 */

public class UserBean {


    User user;
    boolean selected;

    public UserBean(User user)
    {
        this.user = user;
        selected = false;
    }

    /**
     * makes a shallow clone
     * @param userBeanToClone
     */
    public UserBean(UserBean userBeanToClone) {
        this(
                new User(
                    userBeanToClone.getId(),
                    userBeanToClone.getFname(),
                    userBeanToClone.getLname(),
                    userBeanToClone.getEmail(),
                    userBeanToClone.getPassword(),
                    UserLevel.getLevelId(userBeanToClone.getLevel())
                    )
        );
        this.setSelected(userBeanToClone.getSelected());
     }

    @PostConstruct
    public void init()
    {
        user = new User();
    }

        /**
     * Get user's id.
     * @return User's id.
     */
    public long getId(){
        return user.getId();
    }

    /**
     * Set user's id
     * @param id
     */
    public void setId(long id){
        user.setId(id);
    }

    /**
     * Get user's first name.
     * @return user's first name.
     */
    public String getFname() {
        return user.getFname();
    }

    /**
     * Set user's first name.
     * @param fname
     */
    public void setFname(String fname) {
        user.setFname(fname);
    }

    /**
     * Get user's last name.
     * @return user's last name.
     */
    public String getLname() {
        return user.getLname();
    }

    /**
     * Set user's last name.
     * @param lname
     */
    public void setLname(String lname) {
        user.setLname(lname);
    }

    /**
     * Get user's email.
     * @return user's email.
     */
    public String getEmail() {
        return user.getEmail();
    }

    /**
     * Set user's email.
     * @param email
     */
    public void setEmail(String email) {
        user.setEmail(email);
    }

    /**
     * Get user's password.
     * @return
     */
    public String getPassword() {
        return user.getPassword();
    }

    /**
     * Set user's password.
     * @param password
     */
    public void setPassword(String password) {
        user.setPassword(password);
    }

    /**
     * Get user's level.
     * @return user's level.
     */
    public String getLevel() {
        return UserLevel.getLevelName(user.getLevel());
    }

    /**
     * Set user's level.
     * @param level
     */
    public void setLevel(String level) {
        user.setLevel(UserLevel.getLevelId(level));
        }

    /**
     * get selection
     * @return
     */

    public boolean getSelected()
    {
        // for debugging
        //System.out.println("getSelecten");
        return selected;
    }
    /**
     * get selection
     * @param selected
     */
    public void setSelected(boolean selected)
    {
        // for debugging
        //if(selected == true) System.out.println(user.getId() + "Selected");
        //if(selected == false) System.out.println(user.getId() + "unselected");
        this.selected = selected;
    }

    public void setUser(User user)
    {
        this.user = user;
    }

    public User getUser()
    {
        return user;
    }

}
